<template>
  <div
    v-if="dialogTableVisible1"
    :fullscreen="false"
    :modal="false"
    :show-close="false"
    :width="screenWidth + 20 + 'px'"
    :append-to-body="true"
    style="
      position: absolute;
      left: 6rem;
      margin-top: 42px;
      z-index: 10;
      background-color: white;
    "
    :close-on-click-modal="false"
  >
    <div :style="{ width: screenWidth - 96 + 'px' }">
      <div
        :style="{
          height: '40px',
          borderBottom: '1px solid #ccc',
          width: '100%',
        }"
      >
        <div style="position: absolute; right: 15px">
          <el-button @click="flushed" type="primary"> 刷新</el-button>
          <!-- <el-button v-if="Permission" @click="upButton" type="primary">
        修改业务员</el-button
      > -->
          <el-button @click="addRow" type="primary">增行</el-button>
          <el-button @click="() => openRatify('2', '5', '请确认签批')" type="success">
            签批</el-button
          >
          <el-button @click="deleteSelectedRows" type="danger">删除</el-button>
          <el-button
            type="primary"
            @click="getAllData(ruleFormRef)"
            v-if="showInsertButton"
            >保存</el-button
          >
          <el-button
            :disabled="isDis"
            type="primary"
            @click="updateMaterialsFixed(ruleFormRef)"
            v-if="!showInsertButton"
            >保存</el-button
          >

          <el-button @click="OFFdialogTableVisible" type="danger">关闭</el-button>
        </div>
      </div>
    </div>

    <div
      ref="titleDiv"
      :style="{
        backgroundColor: 'rgba(247, 247, 247, 0.903)',
        height: 150 + 'px',
        width: screenWidth - 96 + 'px',
      }"
    >
      <div
        :style="{
          backgroundColor: 'rgba(247, 247, 247,1)',
          height: 163 + 'px',
          width: screenWidth - 96 + 'px',
        }"
      >
        <el-form :model="formMainTable" :inline="true">
          <el-row :gutter="0">
            <el-form-item class="labs" style="margin-right: 0">
              <label class="lab" style="width: 100px; padding-right: 5px">
                单据编号</label
              >
              <el-input
                style="width: 180px"
                v-model="formMainTable.code"
                disabled
                placeholder="自动添加"
              />
            </el-form-item>
            <el-form-item class="labs" style="margin-right: 0">
              <label class="lab" style="width: 100px; padding-right: 5px">
                单据日期
              </label>
              <el-input
                style="width: 180px"
                v-model="formMainTable.f_date"
                disabled
                placeholder="自动添加"
              />
            </el-form-item>
            <el-form-item class="labs" style="margin-right: 0">
              <label class="lab" style="width: 100px; padding-right: 5px">
                业务人员工号
              </label>
              <el-input
                style="width: 180px"
                v-model="formMainTable.busPersonCode"
                @click="openWorkOrderCode()"
                placeholder="自动添加"
              />
            </el-form-item>
            <el-form-item class="labs" style="margin-right: 0">
              <label class="lab" style="width: 100px; padding-right: 5px">
                业务人员
              </label>
              <el-input
                style="width: 180px"
                v-model="formMainTable.user_name"
                disabled
                placeholder="自动添加"
              />
            </el-form-item>
            <el-form-item class="labs" style="margin-right: 0">
              <label class="lab" style="width: 100px; padding-right: 5px">
                业务部门名称
              </label>
              <el-input
                style="width: 180px"
                disabled
                v-model="formMainTable.busDeptName"
                placeholder="自动添加"
              />
            </el-form-item>
          </el-row>
          <el-row :gutter="0">
            <el-form-item class="labs" style="margin-right: 0; display: none">
              <label class="lab" style="width: 100px; padding-right: 5px">
                工单类型</label
              >
              <el-select
                v-model="formMainTable.p_type"
                style="width: 180px"
                :readonly="true"
              >
                <el-option label="正常" value="0"></el-option>
                <el-option label="调整" value="1"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item class="labs" style="margin-right: 0">
              <label class="lab" style="width: 100px; padding-right: 5px">
                业务类型</label
              >
              <el-select
                v-model="formMainTable.f_type"
                style="width: 180px"
                :readonly="true"
                @click="ftypeClick()"
              >
                <el-option label="磨削" value="0"></el-option>
                <!-- <el-option label="领料领回" value="1"></el-option> -->
                <!-- <el-option label="启用领回" value="2"></el-option>
              <el-option label="维修领回" value="3"></el-option> -->
                <!-- <el-option label="先拆后安" value="3"></el-option> -->
              </el-select>
            </el-form-item>

            <el-form-item class="labs" style="margin-right: 0; display: none">
              <label class="lab" style="width: 100px; padding-right: 5px"> 料架</label>
              <el-input
                style="width: 180px"
                :readonly="true"
                v-model="formMainTable.rack_num"
                placeholder="请选择"
                @click="openWorkOrderCode10()"
              />
            </el-form-item>

            <el-form-item class="labs" style="margin-right: 0">
              <label class="lab" style="width: 100px; padding-right: 5px"
                ><span style="color: red">*</span>

                作业设备
              </label>
              <el-input
                style="width: 180px"
                :readonly="true"
                @click="openWorkOrderCode7()"
                v-model="formMainTable.oper_equipmentName"
                placeholder="请选择"
              />
            </el-form-item>
            <el-form-item class="labs" style="margin-right: 0">
              <label class="lab" style="width: 100px; padding-right: 5px"
                ><span style="color: red">*</span>

                作业日期
              </label>
              <el-date-picker
                v-model="formMainTable.oper_date"
                style="width: 180px"
                type="date"
                value-format="YYYY-MM-DD"
              />
            </el-form-item>
            <el-form-item class="labs" style="margin-right: 0">
              <label class="lab" style="width: 100px; padding-right: 5px">
                <span style="color: red; font-weight: 700">*</span>作业班别</label
              >
              <el-select
                v-model="organizationSelect"
                size="medium"
                style="width: 180px"
                clearable
                @change="clickOrganizationSelect()"
              >
                <el-option
                  v-for="item in options"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-row>
          <el-row :gutter="0">
            <el-form-item class="labs" style="margin-right: 0">
              <label class="lab" style="width: 100px; padding-right: 5px"
                ><span style="color: red">*</span>

                作业班组
              </label>
              <el-input
                style="width: 180px"
                :readonly="true"
                v-model="formMainTable.oper_teamName"
                placeholder="请选择"
                @click="openWorkOrderCode2()"
              />
            </el-form-item>
            <el-form-item class="labs" style="margin-right: 0">
              <label class="lab" style="width: 100px; padding-right: 5px"
                ><span style="color: red">*</span>

                作业人员
              </label>
              <el-input
                style="width: 180px"
                :readonly="true"
                v-model="formMainTable.oper_personName"
                placeholder="请选择"
                @click="openWorkOrderCode2()"
              />
            </el-form-item>
            <el-form-item class="labs" style="margin-right: 0; display: none">
              <label class="lab" style="width: 100px; padding-right: 5px"
                ><span style="color: red">*</span>

                实际开始时间</label
              >
              <el-date-picker
                v-model="formMainTable.actual_b_date"
                style="width: 200px"
                type="datetime"
              />
            </el-form-item>
            <el-form-item class="labs" style="margin-right: 0; display: none">
              <label class="lab" style="width: 100px; padding-right: 5px"
                ><span style="color: red">*</span> 实际结束时间</label
              >
              <el-date-picker
                v-model="formMainTable.actual_e_date"
                style="width: 200px"
                type="datetime"
              />
            </el-form-item>
            <el-form-item class="labs" style="margin-right: 0; display: none">
              <label class="lab" style="width: 100px; padding-right: 5px">
                工时时长</label
              >
              <el-input
                style="width: 180px"
                v-model="formMainTable.actual_work_hour"
                @blur="() => handleBlur('actual_work_hour')"
              />
            </el-form-item>
          </el-row>
          <el-row :gutter="0">
            <!-- <el-form-item v-if="false" class="labs" style="margin-right: 0">
            <label class="lab" style="width: 100px; padding-right: 5px"> 签批原因 </label>
            <el-input
              style="width: 465px"
              v-model="formMainTable.ratify_explain"
              :disabled="isRatifyDesc"
            />
          </el-form-item>
          <el-form-item class="labs" style="margin-right: 0">
            <label class="lab" style="width: 100px; padding-right: 5px"> 签批意见 </label>
            <el-input
              style="width: 465px"
              v-model="formMainTable.ratify_desc"
              :disabled="isRatifyDesc"
            />
          </el-form-item> -->
            <el-form-item class="labs" style="margin-right: 0">
              <label class="lab" style="width: 100px; padding-right: 5px"> 备注 </label>
              <el-input style="width: 465px" v-model="formMainTable.remark" />
            </el-form-item>
          </el-row>
        </el-form>
        <el-row :gutter="0">
          <el-form-item class="labs" style="margin-right: 0">
            <label class="lab" style="width: 100px; padding-right: 5px"
              ><span style="color: red; font-weight: 700">*</span> 加工方式</label
            >
            <el-select
              v-model="formMainTable.oper_mode"
              style="width: 180px"
              :readonly="true"
            >
              <!-- <el-option label="自制" value="0"></el-option> -->
              <el-option label="委外" value="1"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item class="labs" style="margin-right: 0">
            <label class="lab" style="width: 100px; padding-right: 5px">
              <span style="color: red; font-weight: 700">*</span> 委外供应商
            </label>
            <el-input
              style="width: 180px"
              :readonly="true"
              v-model="formMainTable.supplier_name"
              placeholder="请选择"
              @click="openWorkOrderCode11()"
            />
          </el-form-item>
        </el-row>
      </div>
      <el-table
        ref="multipleTableRef"
        :data="tableData1"
        stripe
        border
        style="width: 100%"
        :row-style="{ height: '20px' }"
        :height="childTableHeight + 'px'"
        :max-height="childTableHeight + 'px'"
        :cell-style="cellStyle1"
        @selection-change="handleSelectionChange1"
        :header-cell-style="headerCellStyle1"
      >
        <el-table-column type="selection" fixed width="55" align="center" />
        <el-table-column label="行号" fixed width="50" align="center">
          <template #default="{ $index }">
            <span>{{ $index + 1 }}</span>
          </template>
        </el-table-column>
        <el-table-column fixed label="单件唯一码" width="150" align="center">
          <template #header="{ column }">
            <span>
              {{ column.label }} <span style="color: red; font-weight: 700">*</span>
            </span>
          </template>
          <template #default="{ row, $index }">
            <el-input
              :readonly="true"
              @click="openWorkOrderCode1($index)"
              v-model="row.unique_code"
              :style="{ height: '25px' }"
            />
          </template>
        </el-table-column>
        <!-- <el-table-column fixed label="磨削数量" width="100" align="center">
          <template #header="{ column }">
            <span>
              {{ column.label }}
            </span>
          </template>
          <template #default="{ row, $index }">
            <el-input
              @blur="() => handleBlur2('grind_quantity', $index)"
              v-model="row.grind_quantity"
              :style="{ height: '25px' }"
            />
          </template>
        </el-table-column> -->
        <!-- <el-table-column
          style="margin-right: 0;"
          fixed
          label="料架"
          width="100"
          align="center"
        >
          <template #header="{ column }">
            <span>
              {{ column.label }}
            </span>
          </template>
          <template #default="{ row, $index }">
            <el-input
              @click="openWorkOrderCode9($index)"
              v-model="row.rack_num"
              :style="{ height: '25px' }"
            />
          </template>
        </el-table-column> -->
        <!-- <el-table-column fixed label="实际开始时间" width="200" align="center">
          <template #header="{ column }">
            <span>
              {{ column.label }}
            </span>
          </template>
          <template #default="{ row, $index }">
            <el-date-picker
              v-model="row.e_actual_b_date"
              :style="{ height: '25px' }"
              type="datetime"
              format="YYYY-MM-DD hh:mm:ss"
            />
          </template>
        </el-table-column>
        <el-table-column fixed label="实际结束时间" width="200" align="center">
          <template #header="{ column }">
            <span>
              {{ column.label }}
            </span>
          </template>
          <template #default="{ row, $index }">
            <el-date-picker
              v-model="row.e_actual_e_date"
              :style="{ height: '25px' }"
              type="datetime"
              format="YYYY-MM-DD hh:mm:ss"
            />
          </template>
        </el-table-column>
        <el-table-column fixed label="实际工时时长" width="150" align="center">
          <template #header="{ column }">
            <span>
              {{ column.label }}
            </span>
          </template>
          <template #default="{ row, $index }">
            <el-input
              @blur="() => handleBlur1('e_actual_work_hour', $index)"
              v-model="row.e_actual_work_hour"
              :style="{ height: '25px' }"
            />
          </template>
        </el-table-column> -->
        <el-table-column label="所属组号" width="100" align="center">
          <template #header="{ column }">
            <span>{{ column.label }}</span>
          </template>
          <template #default="{ row, $index }">
            <div :style="{ height: '25px' }">{{ row.group_code }}</div>
          </template>
        </el-table-column>
        <el-table-column label="基本信息" align="center">
          <el-table-column label="设备结构" width="100" align="center">
            <template #header="{ column }">
              <span>{{ column.label }}</span>
            </template>
            <template #default="{ row, $index }">
              <div :style="{ height: '25px' }">{{ row.structureName }}</div>
            </template>
          </el-table-column>
          <el-table-column label="零件名称" width="100" align="center">
            <template #header="{ column }">
              <span>{{ column.label }}</span>
            </template>
            <template #default="{ row, $index }">
              <div :style="{ height: '25px' }">{{ row.ecs_name }}</div>
            </template>
          </el-table-column>
          <el-table-column label="型号" width="100" align="center">
            <template #header="{ column }">
              <span>{{ column.label }}</span>
            </template>
            <template #default="{ row, $index }">
              <div :style="{ height: '25px' }">{{ row.model_name }}</div>
            </template>
          </el-table-column>
          <el-table-column label="规格" width="100" align="center">
            <template #header="{ column }">
              <span>{{ column.label }}</span>
            </template>
            <template #default="{ row, $index }">
              <div :style="{ height: '25px' }">{{ row.specification }}</div>
            </template>
          </el-table-column>
        </el-table-column>
        <!-- <el-table-column label="结构数量" align="center">
          <el-table-column label="单位" width="100" align="center">
            <template #header="{ column }">
              <span>{{ column.label }}</span>
            </template>
            <template #default="{ row, $index }">
              <div :style="{ height: '25px' }">{{ row.unit }}</div>
            </template>
          </el-table-column>
          <el-table-column label="结构数量" width="100" align="center">
            <template #header="{ column }">
              <span>{{ column.label }}</span>
            </template>
            <template #default="{ row, $index }">
              <div :style="{ height: '25px' }">{{ row.structure_quantity }}</div>
            </template>
          </el-table-column>
          <el-table-column label="结构组数" width="100" align="center">
            <template #header="{ column }">
              <span>{{ column.label }}</span>
            </template>
            <template #default="{ row, $index }">
              <div :style="{ height: '25px' }">{{ row.structure_group_quantity }}</div>
            </template>
          </el-table-column>
        </el-table-column> -->
        <!-- <el-table-column fixed="right" label="工艺标准" align="center">
          <el-table-column label="工艺编码" width="80" align="center">
            <template #header="{ column }">
              <span>{{ column.label }}</span>
            </template>
            <template #default="{ row, $index }">
              <div :style="{ height: '25px' }">{{ row.processCode }}</div>
            </template>
          </el-table-column>
          <el-table-column label="工艺名称" width="300" align="center">
            <template #header="{ column }">
              <span>{{ column.label }}</span>
            </template>
            <template #default="{ row, $index }">
              <div :style="{ height: '25px' }">{{ row.processName }}</div>
            </template>
          </el-table-column>
        </el-table-column> -->
        <el-table-column label="粗糙度(um)" align="center">
          <el-table-column label="标准" width="100" align="center">
            <template #header="{ column }">
              <span>{{ column.label }}</span>
            </template>
            <template #default="{ row, $index }">
              <div :style="{ height: '25px' }">{{ row.roughnessStandard }}</div>
            </template>
          </el-table-column>
          <el-table-column label="上限" width="100" align="center">
            <template #header="{ column }">
              <span>{{ column.label }}</span>
            </template>
            <template #default="{ row, $index }">
              <div :style="{ height: '25px' }">{{ row.roughnessToleranceUpper }}</div>
            </template>
          </el-table-column>
          <el-table-column label="下限" width="100" align="center">
            <template #header="{ column }">
              <span>{{ column.label }}</span>
            </template>
            <template #default="{ row, $index }">
              <div :style="{ height: '25px' }">{{ row.roughnessToleranceLower }}</div>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="单次磨削(mm)" align="center">
          <el-table-column label="标准" width="100" align="center">
            <template #header="{ column }">
              <span>{{ column.label }}</span>
            </template>
            <template #default="{ row, $index }">
              <div :style="{ height: '25px' }">{{ row.grindStandard }}</div>
            </template>
          </el-table-column>
          <el-table-column label="上限" width="100" align="center">
            <template #header="{ column }">
              <span>{{ column.label }}</span>
            </template>
            <template #default="{ row, $index }">
              <div :style="{ height: '25px' }">{{ row.grindToleranceUpper }}</div>
            </template>
          </el-table-column>
          <el-table-column label="下限" width="100" align="center">
            <template #header="{ column }">
              <span>{{ column.label }}</span>
            </template>
            <template #default="{ row, $index }">
              <div :style="{ height: '25px' }">{{ row.grindToleranceLower }}</div>
            </template>
          </el-table-column>
        </el-table-column>
        <!-- <el-table-column label="数量" width="100" align="center">
          <template #header="{ column }">
            <span>{{ column.label }}</span>
          </template>
          <template #default="{ row, $index }">
            <div :style="{ height: '25px' }">{{ row.quantity }}</div>
          </template>
        </el-table-column> -->

        <!-- <el-table-column label="所属组号" width="100" align="center">
          <template #header="{ column }">
            <span>
              {{ column.label }}
            </span>
          </template>
          <template #default="{ row, $index }">
            <el-input v-model="row.group_code" :style="{ height: '25px' }" />
          </template>
        </el-table-column>
        <el-table-column label="基本信息" align="center">
          <el-table-column label="设备结构" width="100" align="center">
            <template #header="{ column }">
              <span>
                {{ column.label }}
              </span>
            </template>
            <template #default="{ row, $index }">
              <el-input v-model="row.structureName" :style="{ height: '25px' }" />
            </template>
          </el-table-column>
          <el-table-column label="零件名称" width="100" align="center">
            <template #header="{ column }">
              <span>
                {{ column.label }}
              </span>
            </template>
            <template #default="{ row, $index }">
              <el-input v-model="row.ecs_name" :style="{ height: '25px' }" />
            </template>
          </el-table-column>
          <el-table-column label="型号" width="100" align="center">
            <template #header="{ column }">
              <span>
                {{ column.label }}
              </span>
            </template>
            <template #default="{ row, $index }">
              <el-input v-model="row.model_name" :style="{ height: '25px' }" />
            </template>
          </el-table-column>
          <el-table-column label="规格" width="100" align="center">
            <template #header="{ column }">
              <span>
                {{ column.label }}
              </span>
            </template>
            <template #default="{ row, $index }">
              <el-input v-model="row.specification" :style="{ height: '25px' }" />
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="结构数量" align="center">
          <el-table-column label="单位" width="100" align="center">
            <template #header="{ column }">
              <span>
                {{ column.label }}
              </span>
            </template>
            <template #default="{ row, $index }">
              <el-input v-model="row.unit" :style="{ height: '25px' }" />
            </template>
          </el-table-column>
          <el-table-column label="结构数量" width="100" align="center">
            <template #header="{ column }">
              <span>
                {{ column.label }}
              </span>
            </template>
            <template #default="{ row, $index }">
              <el-input v-model="row.structure_quantity" :style="{ height: '25px' }" />
            </template>
          </el-table-column>
          <el-table-column label="结构组数" width="100" align="center">
            <template #header="{ column }">
              <span>
                {{ column.label }}
              </span>
            </template>
            <template #default="{ row, $index }">
              <el-input
                v-model="row.structure_group_quantity"
                :style="{ height: '25px' }"
              />
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column fixed="right" label="工艺标准" align="center">
          <el-table-column label="工艺编码" width="80" align="center">
            <template #header="{ column }">
              <span>
                {{ column.label }}
              </span>
            </template>
            <template #default="{ row, $index }">
              <el-input v-model="row.processCode" :style="{ height: '25px' }" />
            </template>
          </el-table-column>
          <el-table-column label="工艺名称" width="300" align="center">
            <template #header="{ column }">
              <span>
                {{ column.label }}
              </span>
            </template>
            <template #default="{ row, $index }">
              <el-input v-model="row.processName" :style="{ height: '25px' }" />
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="粗糙度" align="center">
          <el-table-column label="标准" width="100" align="center">
            <template #header="{ column }">
              <span>
                {{ column.label }}
              </span>
            </template>
            <template #default="{ row, $index }">
              <el-input v-model="row.roughnessStandard" :style="{ height: '25px' }" />
            </template>
          </el-table-column>
          <el-table-column label="上限" width="100" align="center">
            <template #header="{ column }">
              <span>
                {{ column.label }}
              </span>
            </template>
            <template #default="{ row, $index }">
              <el-input
                v-model="row.roughnessToleranceUpper"
                :style="{ height: '25px' }"
              />
            </template>
          </el-table-column>

          <el-table-column label="下限" width="100" align="center">
            <template #header="{ column }">
              <span>
                {{ column.label }}
              </span>
            </template>
            <template #default="{ row, $index }">
              <el-input
                v-model="row.roughnessToleranceLower"
                :style="{ height: '25px' }"
              />
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="单次磨削" align="center">
          <el-table-column label="标准" width="100" align="center">
            <template #header="{ column }">
              <span>
                {{ column.label }}
              </span>
            </template>
            <template #default="{ row, $index }">
              <el-input v-model="row.grindStandard" :style="{ height: '25px' }" />
            </template>
          </el-table-column>
          <el-table-column label="上限" width="100" align="center">
            <template #header="{ column }">
              <span>
                {{ column.label }}
              </span>
            </template>
            <template #default="{ row, $index }">
              <el-input v-model="row.grindToleranceUpper" :style="{ height: '25px' }" />
            </template>
          </el-table-column>

          <el-table-column label="下限" width="100" align="center">
            <template #header="{ column }">
              <span>
                {{ column.label }}
              </span>
            </template>
            <template #default="{ row, $index }">
              <el-input v-model="row.grindToleranceLower" :style="{ height: '25px' }" />
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="数量" width="100" align="center">
          <template #header="{ column }">
            <span>
              {{ column.label }}
            </span>
          </template>
          <template #default="{ row, $index }">
            <el-input v-model="row.quantity" :style="{ height: '25px' }" />
          </template>
        </el-table-column> -->
        <el-table-column width="300" label="备注" align="left">
          <template #header="{ column }">
            <span>
              {{ column.label }}
            </span>
          </template>
          <template #default="{ row, $index }">
            <el-input v-model="row.e_remark" :style="{ height: '25px' }" />
          </template>
        </el-table-column>
        <el-table-column fixed="right" label="按钮" width="100" align="center">
          <template #default="{ row, $index }">
            <el-button
              :style="{ height: '25px' }"
              type="danger"
              size="mini"
              @click="deleteRow(row)"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
  <el-container>
    <el-header height="65px" :style="{ 'border-bottom': '1px solid #ccc' }">
      <!-- 头部按钮 -->
      <el-row type="flex" justify="end" style="background-color: rgb(211, 227, 253)">
        <div>
          <el-button @click="searchButton" type="primary"> 查询</el-button>
          <el-button @click="openInseart" type="success"> 新增</el-button>
          <el-button @click="() => openRatify('2', '5', '请确认签批')" type="success">
            签批</el-button
          >
          <el-button @click="() => openRatify('2', '6', '请确认弃签')" type="success">
            弃签</el-button
          >
          <el-button @click="() => openRatify('1', '3', '请确认审核')" type="warning">
            审核</el-button
          >
          <el-button @click="() => openRatify('1', '4', '请确认弃审')" type="warning">
            弃审</el-button
          >
          <el-button @click="() => openRatify('1', '9', '请确认删除')" type="danger">
            删除</el-button
          >
        </div>
        <!-- <div class="title">需求汇总统计表</div> -->
      </el-row>
      <div
        style="
          margin-left: 6rem;
          height: 30px;

          background: rgb(241, 244, 243);
          margin-bottom: 0;
          position: relative;
          display: flex;
          justify-content: flex-start;
        "
      >
        <!-- inputCode -->
        <el-input
          style="width: 10%; height: 25px; margin-left: 2px; margin-top: 2px"
          v-model="code"
          placeholder="单据编号"
        >
          <template #prefix>
            <el-icon class="">
              <search />
            </el-icon>
          </template>
        </el-input>
        <div class="block">
          <el-date-picker
            v-model="bfdate"
            style="height: 25px; margin-left: 2px; margin-top: 2px"
            type="date"
            placeholder="开始时间"
            size="small"
            value-format="YYYY-MM-DD"
          />
        </div>
        <div class="block">
          <el-date-picker
            v-model="efdate"
            style="height: 25px; margin-left: 2px; margin-top: 2px"
            type="date"
            placeholder="结束时间"
            size="small"
            value-format="YYYY-MM-DD"
          />
        </div>
        <el-input
          style="width: 10%; height: 25px; margin-left: 2px; margin-top: 2px"
          v-model="userName"
          placeholder="业务员名称"
        >
          <template #prefix>
            <el-icon class="">
              <search />
            </el-icon>
          </template>
        </el-input>
        <el-select
          style="width: 10%; height: 25px; margin-left: 2px; margin-top: 2px"
          v-model="state"
          placeholder="状态"
          clearable
          size="small"
        >
          <el-option label="未审核" value="0"></el-option>
          <el-option label="已审核" value="1"></el-option>
        </el-select>
        <el-select
          style="width: 10%; height: 25px; margin-left: 2px; margin-top: 2px"
          v-model="isRatify"
          placeholder="是否需要签批"
          clearable
          size="small"
        >
          <el-option label="否" value="0"></el-option>
          <el-option label="是" value="1"></el-option>
        </el-select>
        <el-select
          style="width: 10%; height: 25px; margin-left: 2px; margin-top: 2px"
          v-model="ratifyState"
          placeholder="签批状态"
          clearable
          size="small"
        >
          <el-option label="未签批" value="0"></el-option>
          <el-option label="已签批" value="1"></el-option>
          <el-option label="————————" value="-1"></el-option>
        </el-select>
        <el-input
          style="width: 10%; height: 25px; margin-left: 2px; margin-top: 2px"
          v-model="codeSingle"
          placeholder="单据编号(精确)"
        >
          <template #prefix>
            <el-icon class="">
              <search />
            </el-icon>
          </template>
        </el-input>
      </div>
    </el-header>
    <el-container>
      <el-container>
        <el-main style="padding: 2px 2px 0 2px; margin-left: 6rem">
          <el-table
            v-loading="loading"
            ref="table"
            :data="tableData"
            border
            stripe
            :cell-style="cellStyle"
            :header-cell-style="headerCellStyle"
            @selection-change="handleSelectionChange"
            @row-dblclick="handleRowClick"
            @row-click="RowClick"
            :row-style="rowState"
            :row-key="(row: any) => row.id"
            :max-height="screenHeight"
            :height="screenHeight"
            :max-width="'300px'"
          >
            <el-table-column fixed type="index" width="80" align="center" />
            <el-table-column fixed type="selection" width="50" align="center" />

            <el-table-column prop="code" label="单据编号" width="120" align="center" />
            <el-table-column prop="f_date" label="单据日期" width="120" align="center" />
            <el-table-column
              prop="f_type_name"
              label="业务类型"
              width="120"
              align="center"
            />
            <el-table-column
              prop="state_name"
              label="审核状态"
              width="120"
              align="center"
            />
            <!-- <el-table-column
              prop="isRatifyName"
              label="是否需要签批"
              width="120"
              align="center"
            /> -->
            <el-table-column
              prop="ratify_state_name"
              label="签批状态"
              width="120"
              align="center"
            />
            <el-table-column
              prop="user_name"
              label="业务员名称"
              width="80"
              align="center"
            />
            <el-table-column
              prop="user_code"
              label="业务员工号"
              width="120"
              align="center"
            />
            <el-table-column
              prop="dept_name"
              label="部门名称"
              width="120"
              align="center"
            />
            <el-table-column
              prop="create_person_name"
              label="创建人"
              width="120"
              align="center"
            />
            <el-table-column
              prop="f_create_datatime"
              label="创建时间"
              width="200"
              align="center"
            />
            <el-table-column
              prop="ratify_person_name"
              label="签批人"
              width="120"
              align="center"
            />
            <el-table-column
              prop="f_ratify_datetime"
              label="签批时间"
              width="200"
              align="center"
            />
            <el-table-column
              prop="modify_person_name"
              label="修改人"
              width="120"
              align="center"
            />
            <el-table-column
              prop="f_modify_datetime"
              label="修改时间"
              width="200"
              align="center"
            />
            <el-table-column
              prop="verify_person_name"
              label="审核人"
              width="120"
              align="center"
            />
            <el-table-column
              prop="f_verify_datetime"
              label="审核时间"
              width="200"
              align="center"
            />
            <el-table-column prop="remark" label="备注" width="200" align="center" />
          </el-table>
        </el-main>
        <el-footer style="height: 20px">
          <div class="demo-pagination-block">
            <el-pagination
              v-model:current-page="page"
              v-model:page-size="limit"
              :page-sizes="[50, 500, 1000, 1500, 2000, 8000]"
              :small="true"
              :background="true"
              layout="total, sizes, prev, pager, next, jumper"
              :total="total"
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
            />
          </div>
        </el-footer>
      </el-container>
    </el-container>
  </el-container>
  <SearchTableDialog1
    ref="sed"
    @row-data="handleRowData"
    @row-datas="handleRowDatas"
  ></SearchTableDialog1>
  <EntrustRequest
    ref="sea"
    @row-data="handleRowData1"
    @row-datas="handleRowDatas1"
  ></EntrustRequest>
  <SearchTableDialog6
    ref="seb"
    @row-data="handleRowData2"
    @row-datas="handleRowDatas2"
  ></SearchTableDialog6>
  <SearchTableDialog7
    ref="sec"
    @row-data="handleRowData7"
    @row-datas="handleRowDatas7"
  ></SearchTableDialog7>
  <SearchTableDialog9
    ref="sef"
    @row-data="handleRowData9"
    @row-datas="handleRowDatas9"
  ></SearchTableDialog9>
  <SearchTableDialog10
    ref="seg"
    @row-data="handleRowData10"
    @row-datas="handleRowDatas10"
  ></SearchTableDialog10>
  <SearchTableDialog11
    ref="seh"
    @row-data="handleRowData11"
    @row-datas="handleRowDatas11"
  ></SearchTableDialog11>
</template>
<script setup lang="ts">
import {
  ref,
  watch,
  reactive,
  onMounted,
  onBeforeMount,
  computed,
  nextTick,
  onUnmounted,
  toRefs,
} from "vue";
import { Delete, Edit, Search, Share, Upload, Calendar } from "@element-plus/icons-vue";
import {
  ElButton,
  ElDialog,
  dialogEmits,
  ElMessage,
  ElTable,
  TableColumnCtx,
  ElMessageBox,
} from "element-plus";
import type { FormInstance, FormRules } from "element-plus";

import { CircleCloseFilled } from "@element-plus/icons-vue";
import { useRouter } from "vue-router";
import axios from "../../../axios/axiosInstance.ts";
import Cookies from "js-cookie";
import { format } from "date-fns";
import zhCn from "element-plus/dist/locale/zh-cn.mjs";
// crud封装组件
import * as crud from "../../../components/utils/crud.ts";
import * as newCrud from "../../../components/utils/newCrud.ts";

import SearchTableDialog from "@/components/dialogs/SearchTableDialog.vue";
import SearchTableDialog1 from "@/components/dialogs/SearchTableDialog1.vue";
import SearchTableDialog3 from "@/components/dialogs/SearchTableDialog3.vue";
import EntrustRequest from "@/components/dialogs/EntrustRequest.vue";
import SearchTableDialog6 from "@/components/dialogs/SearchTableDialog6.vue";
import SearchTableDialog7 from "@/components/dialogs/SearchTableDialog7.vue";
import SearchTableDialog9 from "@/components/dialogs/SearchTableDialog9.vue";
import SearchTableDialog10 from "@/components/dialogs/SearchTableDialog10.vue";
import SearchTableDialog11 from "@/components/dialogs/SearchTableDialog11.vue";
import * as notifications from "../../../components/utils/notification.ts";
import Co from "../../../components/utils/t-ui-plus-dev/packages/select-table/src/index.vue";
import moment from "moment";
// 时间
// 获取当前时间
const getCurrentFormattedDateTime = () => {
  const currentDateTime = new Date();

  // 格式化当前时间
  const formattedDateTime = currentDateTime.toLocaleString("zh-CN", {
    year: "numeric",
    month: "2-digit",
    day: "2-digit",
    hour: "2-digit",
    minute: "2-digit",
    second: "2-digit",
  });
  // const formattedDateTime = format(currentDateTime, "YYYY-MM-dd HH:mm:ss");

  return formattedDateTime;
};
// 获取年月日
const getCurrentFormattedDate = () => {
  const currentDateTime = new Date();

  // 格式化当前时间，只获取年月日
  const formattedDate = currentDateTime.toLocaleString("zh-CN", {
    year: "numeric",
    month: "2-digit",
    day: "2-digit",
  });

  return formattedDate;
};
// 权限控制
const searchButtonPermissionsA = ref(false);
const menuId = ref(0);
const buttonVariables = {
  searchButtonPermissionsA,
};
const selectPermissionsButton = () => {
  const userName = Cookies.get("userName");
  axios({
    url: "/select/Permissions/Button",
    method: "post",
    data: {
      userName: userName,
      menuId: menuId.value,
    },
  }).then((res) => {
    res.data.forEach((button) => {
      const buttonName = button.buttonName;
      if (buttonVariables.hasOwnProperty(buttonName)) {
        buttonVariables[buttonName].value = true;
      }
    });
  });
};
selectPermissionsButton();
//权限结束
const tableData = ref([]);
const dialogTableVisible1 = ref(false);
const loading = ref(false);
const page = ref(1);
const limit = ref(50);
const total = ref(50);
// const inputName = ref("");
// const inputCode = ref("");
const code = ref("");
const bfdate = ref("");
const efdate = ref("");
const userName = ref("");
const state = ref("");
const isRatify = ref("");
const ratifyState = ref("");
const codeSingle = ref("");

const selectBusinessDate = computed(() => ({
  info: {
    page: page.value,
    limit: limit.value,
    id: "",
    code: code.value,
    bfdate: bfdate.value,
    efdate: efdate.value,
    userName: userName.value,
    state: state.value,
    is_ratify: isRatify.value,
    ratify_state: ratifyState.value,
    code_single: codeSingle.value,
    b_f_date: "",
    e_f_date: "",
    user_code: "",
    user_name: "",
    dept_code: "",
    dept_name: "",
  },
}));
const getUserId = async () => {
  const userName = Cookies.get("userName");
  const res = await crud.fetchData("UserDe/getUserDe", "post", {
    input5: userName,
  });
  const timestamp = new Date().getTime();
  const fdateTime = moment(timestamp).format("YYYY-MM-DD HH:mm:ss");
  const fdate = moment(timestamp).format("YYYY-MM-DD");
  //登记日期
  formMainTable.value.f_date = fdate;
  //签批人
  formMainTable.value.ratify_person_id = res[0].userId;
  formMainTable.value.ratify_person_name = res[0].userName;
  formMainTable.value.ratify_person_time = fdateTime;
  //制单人
  formMainTable.value.create_person_id = res[0].userId;
  formMainTable.value.create_person_name = res[0].userName;
  formMainTable.value.create_datatime = fdateTime;
  //修改人
  formMainTable.value.modify_person_id = res[0].userId;
  formMainTable.value.modify_person_name = res[0].userName;
  formMainTable.value.modify_datetime = fdateTime;
  //审核人
  formMainTable.value.verify_person_id = res[0].userId;
  formMainTable.value.verify_person_name = res[0].userName;
  formMainTable.value.verify_datetime = fdateTime;
};

const handleSizeChange = (val: number) => {
  selectBusinessType();
};
const handleCurrentChange = (val: number) => {
  selectBusinessType();
};
const searchButton = () => {
  selectBusinessType();
};
const selectBusinessType = async () => {
  loading.value = true;
  try {
    const res = await newCrud.fetchData(
      "/EntrustRequest/getList",
      "post",
      selectBusinessDate.value
    );
    console.log(res);
    if (res.info.length == 0) {
      total.value = 0;
      tableData.value = [];
      loading.value = false;
      return;
    }
    tableData.value = res.info;
    total.value = res.info[0].total;
    loading.value = false;
  } catch (error) {
    loading.value = false;
    console.error("请求失败:", error);
  }
};
selectBusinessType();
// 表格
const headerCellStyle = {
  // E9E9E7
  borderColor: "#B9C9C7",
  backgroundColor: "#F2F4FA", // 表头背景颜色
  fontWeight: "bold", // 表头文字粗细
  color: "#1F2129",
  // padding: "0 0 0 30px",
};
const rowState = (arg) => {
  return {
    height: "20px", // 设置合适的行高值
    fontSize: "12px", // 设置合适的字体大小值
    // color: "black",
  };
};
const RowClick = (row, selection) => {
  table.value.toggleRowSelection(row);
};
const isRatifyDesc = ref(true);
const isDis = ref(false);

const handleRowClick = async (row, selection) => {
  isDis.value = false;
  if (row.state == 1) {
    isDis.value = true;
  }
  await getUserId();
  isRatifyDesc.value = false;
  dialogTableVisible1.value = true;
  showInsertButton.value = false;
  console.log(row);
  const res = await newCrud.fetchData("/EntrustRequest/getInfo", "post", {
    info: {
      id: row.id,
    },
  });
  console.log(res);
  formMainTable.value = { ...formMainTable.value, ...res.info[0] };
  //   formMainTable.value.busPersonCode = res[0].userCode;
  //   formMainTable.value.busDeptName = res[0].deptName;
  tableData1.value = [];
  //   const repairApplicationSubListArray = Object.values(res[0].repairApplicationSubList);
  const processedDataArray = res.entity.map((item) => ({
    ...item,
    e_actual_b_date: item.e_actual_b_date_datetime,
    e_actual_e_date: item.e_actual_e_date_datetime,
  }));
  tableData1.value = [...tableData1.value, ...processedDataArray];
  //   formMainTable.value.busDeptName = res[0].deptName;
  //   formMainTable.value.busPersonCode = res[0].userCode;
  formMainTable.value.busPersonCode = res.info[0].user_code;
  formMainTable.value.busDeptName = res.info[0].dept_name;
  formMainTable.value.f_type = res.info[0].f_type.toString();
  formMainTable.value.oper_mode = res.info[0].oper_mode.toString();

  formMainTable.value.f_date = res.info[0].f_date_info;
  organizationSelect.value = parseInt(formMainTable.value.oper_shift);

  //   tableData1.value = [...tableData1.value, ...repairApplicationSubListArray];

  for (let a = 0; a < 21; a++) {
    addRow();
  }
};

const selectedRows = ref([]);
const table = ref();

const cellStyle = ({ row, column, rowIndex, columnIndex }) => {
  if (selectedRows.value.find((selectedRow) => selectedRow.id === row.id)) {
    return {
      backgroundColor: "#DFF0DB !important",
      borderColor: "#B9C9C7",
      padding: "4px",
    };
  } else {
    return { borderColor: "#B9C9C7", padding: "4px", margin: 0 };
  }
};
const handleSelectionChange = (selection: any) => {
  selectedRows.value = selection;
};
const screenHeight = ref(null);
const screenWidth = ref(null);
const childTableHeight = ref(null);
const dynamicHeight = ref(null);

const getScreenHeight = () => {
  dynamicHeight.value = `${window.innerHeight - 81}`;

  childTableHeight.value = `${window.innerHeight}` - 246;
  screenHeight.value = window.innerHeight - 146;
  screenWidth.value = window.innerWidth;
};
getScreenHeight();
const formMainTableData = ref({
  verifyId: "",
  verifyName: "",
  ratifyId: "",
  ratifyName: "",
  ratify_desc: "",
  field_oper_code: "",
  s_oper_code: "",
  idList: "",
});
const field_oper_code = ref("");
const s_oper_code = ref("");
const requestDataAsid = computed(async () => {
  const userName = Cookies.get("userName");
  const res = await crud.fetchData("UserDe/getUserDe", "post", {
    input5: userName,
  });
  formMainTableData.value.verifyId = res[0].userId;
  formMainTableData.value.verifyName = res[0].userName;
  formMainTableData.value.ratifyId = res[0].userId;
  formMainTableData.value.ratifyName = res[0].userName;
  formMainTableData.value.field_oper_code = field_oper_code.value;
  formMainTableData.value.s_oper_code = s_oper_code.value;
  //签批意见
  formMainTableData.value.ratify_desc = formMainTable.value.ratify_desc;
  //   const idList = selectedRows.value.map((row) => row.id);
  for (var i = 0; i < selectedRows.value.length; i++) {}
  var idList = selectedRows.value.map((row) => row.id).join(",");

  formMainTableData.value.idList = idList;
  return {
    info: formMainTableData.value,
  };
});
const openRatify = async (a, b, c) => {
  await getUserId();
  try {
    const result = await notifications.showConfirmDialog("", c, "success");

    if (!result) {
      return;
    }
    console.log("selectedRows.value.length:" + selectedRows.value.length);

    if (selectedRows.value.length == 0) {
      notifications.showMessage("请至少选择一行进行操作", "error");
      // notifications.showMessage("xxxxxx", "error");
      return;
    }

    //签批意见
    //  formMainTableData.value.ratifyDesc = formMainTable.value.ratifyDesc;

    var idList = selectedRows.value.map((row) => row.id).join(",");
    //  var requestData = await requestDataAsid.value;

    //  console.log("requestData:" + JSON.stringify(requestData));

    const res = await newCrud.sendRequest("/EntrustRequest/stateUp", "post", {
      info: {
        idList: idList,
        bus_code: "48",
        field_oper_code: a,
        s_oper_code: b,
        //签批
        ratify_person_id: formMainTable.value.ratify_person_id,
        ratify_person_name: formMainTable.value.ratify_person_name,
        ratify_person_time: formMainTable.value.ratify_person_time,
        //审核
        verify_person_id: formMainTable.value.verify_person_id,
        verify_person_name: formMainTable.value.verify_person_name,
        verify_datetime: formMainTable.value.verify_datetime,
      },
    });
    if (res.code == 200 || res.code == 1) {
      selectBusinessType();
    }
  } catch (error) {
    console.error("请求失败:", error);
  }
};

const getParentIds = (nodeId) => {
  const parentIds = [];
  let currentNode = asideListData.value.find((node) => node.id === nodeId);
  while (currentNode && currentNode.parentID !== null) {
    parentIds.push(currentNode.id);
    currentNode = asideListData.value.find((node) => node.id === currentNode.parentID);
  }
  return parentIds.reverse();
};

// 新增页面展示
const openInseart = async () => {
  await getUserId();
  isRatifyDesc.value = true;
  const userName = Cookies.get("userName");
  const res = await crud.fetchData("UserDe/getUserDe", "post", {
    input5: userName,
  });
  console.log(res);
  formMainTable.value.busDeptName = res[0].deptName;
  formMainTable.value.busPersonCode = res[0].userCode;
  formMainTable.value.bus_person_id = res[0].userId;
  formMainTable.value.user_name = res[0].userName;
  formMainTable.value.bus_dept_id = res[0].deptID;
  organizationSelect.value = 1;
  dialogTableVisible1.value = true;
  showInsertButton.value = true;
  isRepairApplication.value = false;
  nextTick(() => {
    for (let a = 0; a < 21; a++) {
      addRow();
    }
  });
};

interface RuleForm {
  id: string;
  workOrderCode: string;
  grindingProcessStandard: string;
  supplier: string;
  status: true;
  supplierAddress: string;
}
const form = reactive<RuleForm>({
  id: "",
  workOrderCode: "",
  grindingProcessStandard: "",
  supplier: "",
  supplierAddress: "",
});
const ruleFormRef = ref<FormInstance>();
const rules = reactive<FormRules<RuleForm>>({
  // name: [{ message: "请输入班组名称", trigger: "blur"  }],
});
// 子表展示
const cellStyle1 = ({ row, column, rowIndex, columnIndex }) => {
  return { borderColor: "#B9C9C7", padding: "0px", margin: 0 };
};
const showInsertButton = ref(true);
const multipleTableRef = ref();
const handleSelectionChange1 = (val: any[]) => {};
const handleInput = (prop) => {
  const val = parseFloat(formMainTable.value[prop]);
  if (!isNaN(val) && isFinite(val)) {
    //  const roundedVal = val.toFixed(4);
    const roundedVal = val.toString().match(/^-?\d+(\.\d{0,4})?/)[0];
    formMainTable.value[prop] = roundedVal;
    return;
  }
  formMainTable.value[prop] = 0;
};
const handleInput1 = (row, index, prop) => {
  const val = parseFloat(row[prop]);
  if (!isNaN(val) && isFinite(val)) {
    //  const roundedVal = val.toFixed(4);
    const roundedVal = val.toString().match(/^-?\d+(\.\d{0,4})?/)[0];
    row[prop] = roundedVal;
    return;
  }
  row[prop] = 0;
};
const defaultRowData = {
  eid: "",
  unique_code: "",
  group_code: "",
  single_id: "",
  process_id: "",
  e_remark: "",
  unit_price: "",
  amount: "",
  e_ref_state: "",
  batch_num: "",
  part_id: "",
  equipment_structure_id: "",
  structure_group_quantity: "",
  structure_quantity: "",
  demarcate_num: "",
  used_num: "",
  consumption_quantity: "",
  grind_quantity: "",
  unit: "",
  id: "",
  InitDiameter: "",
  allowManualScrap: "",
  allowManualScrapName: "",
  circulationState: "",
  circulationStateName: "",
  cjr: "",
  cjsj: "",
  closeStatus: "",
  color: "",
  componentID: "",
  structure_group_quantity: "",
  consumableCategory: "",
  consumableCategoryName: "",
  creationTime: "",
  currentStatus: "",
  dateType: "",
  diameter: "",
  ecsName: "",
  structure_quantity: "",
  equipmentId: "",
  equipmentStructureId: "",
  grindStandard: "",
  grindToleranceLower: "",
  grindToleranceUpper: "",
  hardnessStandard: "",
  height: "",
  innerHoleStandard: "",
  inputType: "",
  isdel: "",
  lJGrindingNumber: "",
  lJGrindingTimes: "",
  processCode: "",
  length: "",
  lock: "",
  lockName: "",
  lockTable: "",
  material: "",
  materialCode: "",
  materialStatus: "",
  materialStatusName: "",
  unit: "",
  model: "",
  model_id: "",
  modelName: "",
  nonWorkingFaceOuterDiameterStandard: "",
  partSingleID: "",
  processName: "",
  pscQuantity: "",
  pscid: "",
  quantity: "",
  residualGrindingCapacity: "",
  roughnessStandard: "",
  roughnessToleranceLower: "",
  roughnessToleranceUpper: "",
  rowNum: "",
  sourceMethod: "",
  sourcedjID: "",
  specification: "",
  state: "",
  structureName: "",
  supplierUniqueCode: "",
  taperHeight: "",
  taperLength: "",
  taperStandard: "",
  thicknessStandard: "",
  total: "",
  totalGrindingAmount: "",
  uniqueCode: "",
  weight: "",
  width: "",
  workingFaceLength: "",
  workingFaceOuterDiameterStandard: "",
  rack_num: "", //料架
  rack_entity_id: "",
  group_code: "", //组号
  b_e_table: "",
  b_m_table: "",
  e_actual_b_date: "",
  e_actual_e_date: "",
  e_actual_work_hour: "",
};

const tableData1 = ref([
  {
    ...defaultRowData,
  },
  // More data...
]);

const OFFdialogTableVisible = () => {
  dialogTableVisible1.value = false;
  selectBusinessType();
  flushed();
  //   clearForm();
};
// const clearForm = () => {
//   Object.keys(form).forEach((key) => {
//     if (typeof form[key] === "boolean") {
//       Vue.set(form, key, true);
//     } else {
//       Vue.set(form, key, "");
//     }
//   });
// };

const flushed = async () => {
  //   organizationSelect.value = "";
  //   parentIDValue.value = "";
  //   Object.keys(formMainTable.value).forEach((key) => {
  //     formMainTable.value[key] = "";
  //   });
  formMainTable.value.f_type = "0";
  formMainTable.value.oper_mode = "1";
  formMainTable.value.p_type = "0";

  tableData1.value = [];
  for (let a = 0; a < 21; a++) {
    addRow();
  }
  formMainTable.value.id = "";
  formMainTable.value.code = "";
  formMainTable.value.supplier_id = "";
  formMainTable.value.supplier_name = "";
  formMainTable.value.oper_equipment = "";
  formMainTable.value.oper_equipmentName = "";
  formMainTable.value.oper_date = "";
  formMainTable.value.oper_shift = "1";
  organizationSelect.value = "";
  formMainTable.value.oper_team = "";
  formMainTable.value.oper_teamName = "";
  formMainTable.value.oper_person = "";
  formMainTable.value.oper_personName = "";
  formMainTable.value.ratify_explain = "";
  formMainTable.value.ratify_desc = "";
  formMainTable.value.remark = "";
  formMainTable.value.actual_b_date = "";
  formMainTable.value.actual_e_date = "";
  formMainTable.value.actual_work_hour = "";
};
const addRow = () => {
  tableData1.value.push({ ...defaultRowData });
};
const requestFormTable = computed(() => {
  const usefulDataArray = tableData1.value.filter(
    (item) =>
      item.singleCode !== "" &&
      item.singleCode !== "undefined" &&
      item.singleCode !== null
  );

  const formMainTableDate = formMainTable.value;
  const userName = Cookies.get("userName");
  //   const creationTime: creationTime = getCurrentFormattedDateTime();
  const timestamp = new Date().getTime();
  return {
    userName: userName,
    time: timestamp,
    childList: usefulDataArray,
    formMainTable: formMainTableDate,
  };
});
//必填验证
const isTrue = ref(true);
const isRole = () => {
  isTrue.value = true;
  if (!formMainTable.value.oper_equipment) {
    notifications.showMessage("请选择作业设备", "error");
    return;
  }
  if (!formMainTable.value.oper_date) {
    notifications.showMessage("请选择作业日期", "error");
    return;
  }
  if (!formMainTable.value.oper_team) {
    notifications.showMessage("请选择作业班组", "error");
    return;
  }
  if (!formMainTable.value.oper_person) {
    notifications.showMessage("请选择作业人员", "error");
    return;
  }
  if (formMainTable.value.oper_mode == "1") {
    if (formMainTable.value.supplier_id == "") {
      notifications.showMessage("请先选择委外供应商", "error");
      return;
    }
  }
  const usefulDataArray = tableData1.value.filter(
    (item) =>
      item.unique_code !== "" &&
      item.unique_code !== "undefined" &&
      item.unique_code !== null
  );
  if (usefulDataArray.length == 0) {
    notifications.showMessage("请选择单件唯一码", "error");
    return;
  }

  isTrue.value = false;
};
const requestFormTable1 = computed(() => {
  const usefulDataArray = tableData1.value.filter(
    (item) =>
      item.singleCode !== "" &&
      item.singleCode !== "undefined" &&
      item.singleCode !== null
  );

  const formMainTableDate = formMainTable.value;
  const userName = Cookies.get("userName");
  const timestamp = new Date().getTime();
  const fdate = moment(timestamp).format("YYYY-MM-DD HH:mm:ss");

  const jsonObj = {
    //  userName: userName,
    //  time: timestamp,
    info: formMainTableDate,
    entity: usefulDataArray,
  };
  jsonObj.info["userName"] = userName;
  jsonObj.info["fdate"] = fdate;

  return jsonObj;
});
const updateMaterialsFixed = async () => {
  try {
    await isRole();
    if (isTrue.value) {
      return;
    }

    const result = await notifications.showConfirmDialog("", "请确认保存", "success");

    if (!result) {
      // 用户点击了取消按钮，不执行保存操作
      return;
    }
    formMainTable.value.actual_b_date = formatDate(
      new Date(formMainTable.value.actual_b_date)
    );
    formMainTable.value.actual_e_date = formatDate(
      new Date(formMainTable.value.actual_e_date)
    );
    const formMainTableDate = formMainTable.value;
    const usefulDataArray = tableData1.value.filter(
      (item) =>
        item.unique_code !== "" &&
        item.unique_code !== "undefined" &&
        item.unique_code !== null
    );
    const replaceUndefinedWithEmptyString = (obj) => {
      const newObj = {};
      for (const key in obj) {
        if (Object.prototype.hasOwnProperty.call(obj, key)) {
          newObj[key] = obj[key] === undefined ? "" : obj[key];
        }
      }
      return newObj;
    };
    const cleanedDataArray = usefulDataArray.map((item) =>
      replaceUndefinedWithEmptyString(item)
    );
    //  row_num
    const jsonObj = {
      info: formMainTableDate,
      entity: cleanedDataArray.map((item, index) => {
        return { ...item, row_num: (index + 1).toString() };
      }),
    };
    const res = await newCrud.sendRequest("/EntrustRequest/insert", "post", jsonObj);
    if (res.code == 200 || res.code == 1) {
      OFFdialogTableVisible();
    }

    //  const res = await newCrud.sendRequest(
    //    "/send/upDate",
    //    "post",
    //    requestFormTable1.value
    //  );

    //  if (res.code == 200 || res.code == 1) {
    //    OFFdialogTableVisible();
    //  }
  } catch (error) {
    console.error("请求失败:", error);
  }
};
const formatDate = (date) => {
  if (!date || isNaN(date.getTime())) {
    // 如果日期为空或无效，返回空字符串或默认值
    return "";
  }
  const year = date.getFullYear();
  const month = String(date.getMonth() + 1).padStart(2, "0");
  const day = String(date.getDate()).padStart(2, "0");
  const hours = String(date.getHours()).padStart(2, "0");
  const minutes = String(date.getMinutes()).padStart(2, "0");
  const seconds = String(date.getSeconds()).padStart(2, "0");

  return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
};
const getAllData = async () => {
  try {
    const result = await notifications.showConfirmDialog("", "请确认保存", "success");
    await isRole();
    if (isTrue.value) {
      return;
    }

    if (!result) {
      // 用户点击了取消按钮，不执行保存操作
      return;
    }
    formMainTable.value.actual_b_date = formatDate(
      new Date(formMainTable.value.actual_b_date)
    );
    formMainTable.value.actual_e_date = formatDate(
      new Date(formMainTable.value.actual_e_date)
    );
    const formMainTableDate = formMainTable.value;
    console.log(tableData1.value);
    const usefulDataArray = tableData1.value.filter(
      (item) =>
        item.unique_code !== "" &&
        item.unique_code !== "undefined" &&
        item.unique_code !== null
    );
    const replaceUndefinedWithEmptyString = (obj) => {
      const newObj = {};
      for (const key in obj) {
        if (Object.prototype.hasOwnProperty.call(obj, key)) {
          newObj[key] = obj[key] === undefined ? "" : obj[key];
        }
      }
      return newObj;
    };
    const cleanedDataArray = usefulDataArray.map((item) =>
      replaceUndefinedWithEmptyString(item)
    );
    //  row_num
    const jsonObj = {
      info: formMainTableDate,
      entity: cleanedDataArray.map((item, index) => {
        return { ...item, row_num: (index + 1).toString() };
      }),
    };
    const res = await newCrud.sendRequest("/EntrustRequest/insert", "post", jsonObj);
    if (res.code == 200 || res.code == 1) {
      OFFdialogTableVisible();
    }
  } catch (error) {
    console.error("请求失败:", error);
  }
};

const getSelectedData = () => {
  const selectedRows = multipleTableRef.value.getSelectionRows();
};

const deleteSelectedRows = () => {
  const selectedRows = multipleTableRef.value.getSelectionRows();
  selectedRows.forEach((row) => {
    const index = tableData1.value.indexOf(row);
    if (index !== -1) {
      tableData1.value.splice(index, 1);
    }
  });
};

const deleteRow = (row: any) => {
  const index = tableData1.value.indexOf(row);
  if (index !== -1) {
    tableData1.value.splice(index, 1);
  }
};
const headerCellStyle1 = {
  borderColor: "#B9C9C7",
  backgroundColor: "#F2F4FA",
  fontWeight: "bold",
  color: "#1F2129",
  height: "40px",
  margin: 0,
  padding: 0,
  textAlign: "center",
};
// 弹窗
const indexEmployeeJob = ref(0);
const isRepairApplication = ref(false);
const isdisRepairApplication = ref(false);
const flushed1 = async (value) => {
  formMainTable.value.workTeam = "";
  formMainTable.value.name = "";
  formMainTable.value.repairTime = "";
  formMainTable.value.repairTimeUnit = "";
  formMainTable.value.supplier = "";
  formMainTable.value.supplierAddress = "";
};
const handleValueRangeChange = async (value) => {
  flushed1();
  let repairMode = formMainTable.value.repairMode;
  if (repairMode == "0") {
    isRepairApplication.value = false;
    isdisRepairApplication.value = false;
  } else {
    isRepairApplication.value = true;
    isdisRepairApplication.value = true;
  }
};
const sed = ref<any>(null);
const sea = ref<any>(null);
const seb = ref<any>(null);
const sec = ref<any>(null);
const sef = ref<any>(null);
const seg = ref<any>(null);
const seh = ref<any>(null);

const openWorkOrderCode = async () => {
  sed.value.dialogTableVisible = true;
  await openDial();
};
const openWorkOrderCode1 = async () => {
  sea.value.dialogTableVisible = true;
  await openDial1();
};
const openWorkOrderCode2 = async () => {
  seb.value.dialogTableVisible = true;
  await openDial2();
};
const openWorkOrderCode7 = async () => {
  sec.value.dialogTableVisible = true;
  await openDial7();
};
const index9 = ref(0);
const openWorkOrderCode9 = async (index) => {
  index9.value = index;
  sef.value.dialogTableVisible = true;
  await openDial9();
};
const openWorkOrderCode10 = async (index) => {
  seg.value.dialogTableVisible = true;
  await openDial10();
};
const openWorkOrderCode11 = async (index) => {
  seh.value.dialogTableVisible = true;
  await openDial11();
};
const tableDemo = ref([
  { type: "index", fixed: true, width: "60", align: "center" },
  { prop: "userCode", label: "业务员工号", width: "150", align: "center" },
  { prop: "userName", label: "业务员名称", width: "150", align: "center" },
  { prop: "deptCode", label: "部门编号", width: "150", align: "center" },
  { prop: "deptName", label: "部门名称", width: "150", align: "center" },
  { prop: "description", label: "说明", width: "150", align: "center" },
]);
const tableDemo1 = ref([
  { type: "index", fixed: true, width: "60", align: "center" },
  //   { prop: "id", label: "id", width: "150", align: "center" },
  { prop: "unique_code", label: "单件编号", width: "150", align: "center" },
  //   { prop: "color", label: "颜色", width: "150", align: "center" },
  { prop: "model_name", label: "型号", width: "100", align: "center" },
  { prop: "ecs_name", label: "零件名称", width: "100", align: "center" },
  //   { prop: "materialStatusName", label: "物料状态", width: "100", align: "center" },
  //   { prop: "circulationStateName", label: "流转状态", width: "100", align: "center" },
  { prop: "category_name", label: "零件类别", width: "80", align: "center" },
  { prop: "structureName", label: "结构名称", width: "80", align: "center" },
  //   { prop: "latest_ps_id", label: "最新工艺id", width: "80", align: "center" },
  //   { prop: "default_ps_id", label: "默认工艺id", width: "80", align: "center" },
  //   { prop: "report_ps_id", label: "统计工艺id", width: "80", align: "center" },
  //   { prop: "pg_id", label: "所属组", width: "80", align: "center" },
  { prop: "group_code", label: "所属组号", width: "80", align: "center" },
  //   { prop: "pge_id", label: "所属组子表ID", width: "80", align: "center" },

  //   { prop: "processName", label: "磨削标准", width: "300", align: "center" },
]);
const tableDemo2 = ref([
  { type: "index", fixed: true, width: "60", align: "center" },
  { prop: "teamCode", label: "班组编号", width: "150", align: "center" },
  { prop: "teamName", label: "班组名称", width: "150", align: "center" },
  { prop: "userCode", label: "员工编号", width: "150", align: "center" },
  { prop: "userName", label: "员工名称", width: "150", align: "center" },
  { prop: "deptCode", label: "部门编号", width: "150", align: "center" },
  { prop: "deptName", label: "部门名称", width: "150", align: "center" },
]);
const tableDemo7 = ref([
  { type: "index", fixed: true, width: "60", align: "center" },
  { prop: "equipmentCode", label: "设备编号", width: "150", align: "center" },
  { prop: "equipmentName", label: "设备名称", width: "150", align: "center" },
  { prop: "specificationModel", label: "规格型号", width: "150", align: "center" },
  { prop: "supplier", label: "供应商", width: "150", align: "center" },
  { prop: "description", label: "说明", width: "150", align: "center" },
]);
const tableDemo9 = ref([
  { type: "index", fixed: true, width: "60", align: "center" },
  { prop: "rack_code", label: "料架编号", width: "150", align: "center" },
  { prop: "rack_name", label: "料架名称", width: "150", align: "center" },
  { prop: "rack_num", label: "料架挂号", width: "150", align: "center" },
  { prop: "e_remark", label: "说明", width: "150", align: "center" },
]);
const tableDemo11 = ref([
  { type: "index", fixed: true, width: "60", align: "center" },
  { prop: "supplier_code", label: "供应商编码", width: "150", align: "center" },
  { prop: "supplier_name", label: "供应商名称", width: "150", align: "center" },
]);
const openDial11 = () => {
  seh.value.ifRowChoose = false;
  seh.value.dynamicPlaceholder1 = "供应商编码";
  seh.value.dynamicPlaceholder2 = "供应商名称";
  seh.value.ifdynamic1 = true;
  seh.value.ifdynamic2 = true;
  seh.value.tableColumns = tableDemo11.value;
  seh.value.compareValue = "id";
  seh.value.apiUrl = "PlanGrind/supplier";
  seh.value.searchInput();
};
const openDial10 = () => {
  seg.value.ifRowChoose = false;
  seg.value.ifdynamic12 = true;
  seg.value.dynamicPlaceholder2 = "料架编号";
  seg.value.ifdynamic3 = true;
  seg.value.dynamicPlaceholder3 = "料架名称";

  //   sef.value.input1 = tableData1.value[index9.value].id;
  seg.value.ifdynamic4 = true;
  seg.value.tableColumns = tableDemo9.value;
  seg.value.compareValue = "eid";
  seg.value.apiUrl = "sendBk/getRack";
  seg.value.searchInput();
};
const openDial9 = () => {
  sef.value.ifRowChoose = false;
  sef.value.ifdynamic12 = true;
  sef.value.dynamicPlaceholder2 = "料架编号";
  sef.value.ifdynamic3 = true;
  sef.value.dynamicPlaceholder3 = "料架名称";

  //   sef.value.input1 = tableData1.value[index9.value].id;
  sef.value.ifdynamic4 = true;
  sef.value.tableColumns = tableDemo9.value;
  sef.value.compareValue = "eid";
  sef.value.apiUrl = "sendBk/getRack";
  sef.value.searchInput();
};
const openDial = () => {
  sed.value.ifRowChoose = false;
  sed.value.ifdynamic1 = true;
  sed.value.dynamicPlaceholder1 = "业务员工号";
  sed.value.ifdynamic2 = true;
  sed.value.dynamicPlaceholder2 = "业务员名称";
  sed.value.ifdynamic3 = true;
  sed.value.dynamicPlaceholder3 = "部门编号";
  sed.value.ifdynamic3 = true;
  sed.value.dynamicPlaceholder4 = "部门名称";
  sed.value.ifdynamic4 = true;
  sed.value.tableColumns = tableDemo.value;
  sed.value.compareValue = "userId";
  sed.value.apiUrl = "UserDe/getUserDe";
  sed.value.searchInput();
};
const openDial1 = () => {
  //多选
  sea.value.ifRowChoose = true;

  sea.value.dynamicPlaceholder1 = "单件编号";
  sea.value.dynamicPlaceholder2 = "型号";
  sea.value.dynamicPlaceholder3 = "零件名称";
  sea.value.dynamicPlaceholder4 = "结构名称";
  //   sea.value.dynamicPlaceholder5 = "单件精确";
  //   sea.value.dynamicPlaceholder6 = "快速检索码";
  //   sea.value.dynamicPlaceholder7 = "工单类型";
  sea.value.ifdynamic1 = true;
  sea.value.ifdynamic2 = true;
  sea.value.ifdynamic3 = true;
  sea.value.ifdynamic3 = true;
  sea.value.ifdynamic4 = true;
  sea.value.input = formMainTable.value.f_type;
  sea.value.tableColumns = tableDemo1.value;
  sea.value.compareValue = "id";
  sea.value.input6 = formMainTable.value.oper_mode;
  sea.value.apiUrl = "/EntrustRequest/getSing";
  sea.value.searchInput();
};
const openDial2 = () => {
  seb.value.ifRowChoose = false;
  seb.value.dynamicPlaceholder1 = "员工编号";
  seb.value.dynamicPlaceholder2 = "员工名称";
  seb.value.dynamicPlaceholder3 = "部门编号";
  seb.value.dynamicPlaceholder4 = "部门名称";
  seb.value.dynamicPlaceholder5 = "班组编号";
  seb.value.dynamicPlaceholder6 = "班组名称";
  seb.value.dynamicPlaceholder7 = "班组id";
  seb.value.dynamicPlaceholder8 = "用户编号精确录入";
  seb.value.ifdynamic1 = true;
  seb.value.ifdynamic2 = true;
  seb.value.ifdynamic3 = true;
  seb.value.ifdynamic3 = true;
  seb.value.ifdynamic4 = true;
  seb.value.ifdynamic5 = true;
  seb.value.ifdynamic6 = true;
  seb.value.tableColumns = tableDemo2.value;
  seb.value.compareValue = "userId";
  seb.value.apiUrl = "WOP/getTeamPerson";
  seb.value.searchInput();
};
const openDial7 = () => {
  sec.value.ifRowChoose = false;
  sec.value.dynamicPlaceholder1 = "设备编号";
  sec.value.dynamicPlaceholder2 = "设备名称";
  sec.value.ifdynamic1 = true;
  sec.value.ifdynamic2 = true;
  sec.value.tableColumns = tableDemo7.value;
  sec.value.compareValue = "ID";
  sec.value.apiUrl = "WOP/getEquipment";
  sec.value.searchInput();
};
// const flushed1 = () => {
//   tableData1.value = [];
//   for (let a = 0; a < 21; a++) {
//     addRow();
//   }
// };
const handleRowData11 = async (row) => {
  formMainTable.value.supplier_id = row.id;
  formMainTable.value.supplier_name = row.supplier_name;
};
const handleRowData = async (row) => {
  console.log(row);
  //业务部门
  formMainTable.value.bus_dept_id = row.deptID;
  formMainTable.value.user_name = row.userName;
  formMainTable.value.busDeptName = row.deptName;
  //业务人员
  formMainTable.value.bus_person_id = row.userId;
  formMainTable.value.busPersonCode = row.userCode;
};

const handleRowDatas = (row) => {};
const handleRowDatas1 = (row) => {
  const rowLength = row.length;
  console.log(row);
  if (rowLength == 0) {
    return;
  }
  addRow();
  for (let k = 0; k < row.length; k++) {
    for (let i = 0; i < tableData1.value.length; i++) {
      if (tableData1.value[i].unique_code == row[k].unique_code) {
        notifications.showMessage("第" + (i + 1) + "行单件唯一码重复", "error");
        return;
      }
    }
  }
  for (let i = 0; i < tableData1.value.length; i++) {
    if (
      tableData1.value[i].unique_code == "" ||
      tableData1.value[i].unique_code == undefined
    ) {
      for (let k = 0; k < row.length; k++) {
        tableData1.value[i + k] = { ...tableData1.value[i + k], ...row[k] };
        tableData1.value[i + k].quantity = "1";
        tableData1.value[i + k].process_id = row[k].latest_ps_id;
        //   tableData1.value[i + k].structure_group_quantity = row[k].componentNumber;
        //   tableData1.value[i + k].structure_quantity = row[k].ecs_p_quantity;
        //   tableData1.value[i + k].unit = row[k].ecs_unit;
        tableData1.value[i + k].group_code = row[k].pg_id;
        tableData1.value[i + k].single_id = row[k].id;
      }
      return;
    }
  }
};
const handleRowData2 = async (row) => {
  formMainTable.value.oper_team = row.teamId;
  formMainTable.value.oper_teamName = row.teamName;
  formMainTable.value.oper_person = row.userId;
  formMainTable.value.oper_personName = row.userName;
};
const handleRowData7 = async (row) => {
  formMainTable.value.oper_equipment = row.ID;
  formMainTable.value.oper_equipmentName = row.equipmentName;
};
const findLevelByValue = (options, targetValue) => {
  for (const option of options) {
    // 如果当前选项的值与目标值匹配，则返回该选项的级别
    if (option.value === targetValue) {
      return option.label;
    }
    // 如果当前选项有子选项，则递归调用该函数
    if (option.children && option.children.length > 0) {
      const label = findLevelByValue(option.children, targetValue);
      // 如果在子选项中找到了目标值，则返回找到的级别
      if (label !== undefined) {
        return label;
      }
    }
  }
  // 如果未找到目标值，则返回 undefined
  return undefined;
};
const handleRowData9 = (row) => {
  const rowLength = row.length;
  console.log(row);
  if (rowLength == 0) {
    return;
  }
  tableData1.value[index9.value].rack_entity_id = row.eid;
  tableData1.value[index9.value].rack_num = row.rack_num;
};
const handleRowData10 = (row) => {
  const rowLength = row.length;

  if (rowLength == 0) {
    return;
  }
  console.log("点击行数据: ");
  console.log(row);
  console.log("表格数据:");
  console.log(tableData1.value);
  for (var i = 0; i < tableData1.value.length; i++) {
    //获取tableData1填写unique_code的内容
    if (
      tableData1.value[i].unique_code != "" &&
      tableData1.value[i].unique_code != undefined
    ) {
      //只获取rack_entity_id没有的数据
      if (
        tableData1.value[i].rack_entity_id == "" ||
        tableData1.value[i].rack_entity_id == undefined
      ) {
        tableData1.value[i].rack_entity_id = row.eid;
        tableData1.value[i].rack_num = row.rack_num;
      }
    }
  }
};

// 查询下拉框;
// 组织类型
const options = reactive([
  {
    value: "Option1",
    label: "Option1",
  },
]);

// 定义前端数据模型
const formMainTable = ref({
  id: "",
  // 工单编码，
  code: "",
  // 单据日期，
  f_date: "",
  // 业务人员工号，
  user_name: "",
  busPersonCode: "",
  // 业务部门名称，
  busDeptName: "",
  bus_person_id: "",
  bus_dept_id: "",
  // 计划类型，
  p_type: "0",
  // 工单类型，
  f_type: "0",
  //自制/委外
  oper_mode: "1",
  //委外供应商
  supplier_id: "",
  supplier_name: "",
  // 作业设备，
  oper_equipment: "",
  //作业设备名称
  oper_equipmentName: "",
  // 作业日期，
  oper_date: "",
  // 作业班别，
  //   organizationSelect: "",
  oper_shift: "1",
  // 作业班组，
  oper_team: "",
  oper_teamName: "",
  // 作业人员，
  oper_person: "",
  oper_personName: "",
  // 签批原因，，
  ratify_explain: "",
  // 签批意见，，
  ratify_desc: "",
  // 备注，
  remark: "",
  create_person_id: "",
  create_person_name: "",
  create_datatime: "",
  ratify_person_id: "",
  ratify_person_name: "",
  ratify_person_time: "",
  modify_person_id: "",
  modify_person_name: "",
  modify_datetime: "",
  verify_person_id: "",
  verify_person_name: "",
  verify_datetime: "",
  actual_b_date: "", //指实际开始[安装][拆卸][磨削]所对应的时间点
  actual_e_date: "", //指实际结束[安装][拆卸][磨削]所对应的时间点
  actual_work_hour: "", //开始时间-结束时间
});

const dynamicTitle = ref("展开参数");

//下拉表格
const selectTable = ref();
const stateTable: any = reactive({
  table: {
    total: 0,
    currentPage: 1,
    data: [],
    columns: [
      { prop: "uniqueCode", label: "单件唯一码", width: "150", align: "center" },
      { prop: "equipmentName", label: "设备名称", width: "150", align: "center" },
      {
        prop: "materialCode",
        label: "物料编码",
        width: "150",
        align: "center",
      },
      { prop: "material", label: "材质", width: "150", align: "center" },
      { prop: "specification", label: "规格", width: "150", align: "center" },
      { prop: "model", label: "型号", width: "150", align: "center" },
    ],
  },
});
onMounted(() => {
  getData(1);
});

const uniqueCode = ref("");
const getData = async (pageNum) => {
  const res = await crud.fetchData("/Rep/select/OutsourcingResultList", "post", {
    page: pageNum,
    limit: 1000,
    input2: uniqueCode.value,
  });
  if (res.length == 0) {
    stateTable.table.total = 0;
    stateTable.table.data = [];

    return;
  }
  stateTable.table.data = res;
  stateTable.table.total = res[0].total;
};
// 获取当前的页码
const pageChange = (val) => {
  stateTable.table.currentPage = val;
  getData(val);
};
const handleStatusChange = (row) => {
  let text = row.enableStatus === 1 ? "启用" : "废止";
  ElMessageBox.confirm(`确认要${text}这条数据吗？`, "警告", {
    confirmButtonText: "确定",
    cancelButtonText: "取消",
    type: "warning",
  })
    .then(() => {
      console.log("点击确定");
    })
    .catch(() => {
      console.log("点击取消");
    });
};
const radioChange = async (row) => {
  if (Object.keys(row).length === 0) {
    return;
  }
  addRow();
  for (let i = 0; i < tableData1.value.length; i++) {
    if (
      tableData1.value[i].uniqueCode == "" ||
      tableData1.value[i].uniqueCode == undefined
    ) {
      tableData1.value[i].componentId = row.componentId;
      tableData1.value[i].equipmentStructureId = row.equipmentStructureId;
      tableData1.value[i].material = row.material;
      tableData1.value[i].specification = row.specification;
      tableData1.value[i].model = row.model;
      tableData1.value[i].uniqueCode = row.uniqueCode;

      return;
    } else if (tableData1.value[i].uniqueCode === row.uniqueCode) {
      // Show a warning or handle the duplicate here
      notifications.showMessage("第" + (i + 1) + "单件唯一码重复", "error");
      return;
    }
  }

  selectTable.value.clear();
};
const filterMethod = async (val) => {
  uniqueCode.value = val;
  getData(stateTable.table.currentPage);
};
const handleBlurTable = () => {
  selectTable.value.clear();
};
const rowState1 = (arg) => {
  return {
    height: "20px", // 设置合适的行高值
    fontSize: "12px", // 设置合适的字体大小值
  };
};
const ftypeClick = () => {
  tableData1.value = [];
  for (let a = 0; a < 21; a++) {
    addRow();
  }
};
//动态下拉框
const organizationSelect = ref("");
const transformResToOptions = (res) => {
  return res.map((item) => {
    return {
      value: item.ID,
      label: item.name,
    };
  });
};
// const selectSystem_parameter_sub_tableDate = reactive({
//   tableName: "BusinessDepartmentTypeMappingTable",
//   field: "organizationType",
// });
const selectSystem_parameter_sub_table = async () => {
  try {
    const res = await crud.fetchData("/WOP/getShift", "post", {});
    console.log(res);
    options.splice(0, options.length, ...transformResToOptions(res.info));
  } catch (error) {
    console.error("请求失败:", error);
  }
};
selectSystem_parameter_sub_table();

const clickOrganizationSelect = async () => {
  console.log(organizationSelect.value);
  formMainTable.value.oper_shift = organizationSelect.value;
};
const handleBlur = (fieldName) => {
  const val = formMainTable.value[fieldName];
  if (!isNaN(parseFloat(val)) && isFinite(val)) {
    //  form[prop] = parseFloat(val).toFixed(4);
    const roundedVal = parseFloat(val)
      .toString()
      .match(/^-?\d+(\.\d{0,2})?/)[0];
    formMainTable.value[fieldName] = roundedVal;
    return;
  } else {
    // 如果不是有效数字，清空表单
    formMainTable.value[fieldName] = "";
    return;
  }
};
const handleBlur1 = (fieldName, index) => {
  const val = tableData1.value[index][fieldName];
  if (!isNaN(parseFloat(val)) && isFinite(val)) {
    //  form[prop] = parseFloat(val).toFixed(4);
    const roundedVal = parseFloat(val)
      .toString()
      .match(/^-?\d+(\.\d{0,2})?/)[0];
    tableData1.value[index][fieldName] = roundedVal;
    return;
  } else {
    // 如果不是有效数字，清空表单
    tableData1.value[index][fieldName] = "";
    return;
  }
};
const handleBlur2 = (fieldName, index) => {
  const val = tableData1.value[index][fieldName];
  if (!isNaN(parseFloat(val)) && isFinite(val)) {
    //  form[prop] = parseFloat(val).toFixed(4);
    const roundedVal = parseFloat(val)
      .toString()
      .match(/^-?\d+(\.\d{0,4})?/)[0];
    tableData1.value[index][fieldName] = roundedVal;
    return;
  } else {
    // 如果不是有效数字，清空表单
    tableData1.value[index][fieldName] = "";
    return;
  }
};
</script>
<style scoped>
.el-table {
  /* --el-table-row-hover-bg-color: rgba(0, 158, 250, 0.219) !important; */
  /* --el-table-row-hover-bg-color: #fef5f0 !important; */
  --el-table-row-hover-bg-color: rgba(254, 245, 240, 0.8) !important;
}

/* 选中 */
.el-table {
  /* --el-table-row-hover-bg-color: #fef5f0 !important; */
  --el-table-row-hover-bg-color: rgba(254, 245, 240, 0.8) !important;
}

.down-tree ::v-deep .el-tree-node.is-expanded > .el-tree-node__children {
  display: inline;
}

.down-tree {
  height: 100%;
}

.demo-pagination-block {
  float: right;
}

.custom-dialog {
  position: fixed;
  top: 10em;
  left: 50%;
  width: 20%;
  /* 其他样式... */
}

.demo-form-inline .el-input {
  --el-input-width: 220px;
}

.labs {
  margin-bottom: 0px;
}

.lab {
  background-color: rgba(247, 247, 247, 0.903);
  /* border-radius: 5px; */
  text-align: center;
  margin-bottom: 0px;
  text-align: right;
}
</style>
